Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skipOverflow option #24

Merged
merged 1 commit into from
Dec 14, 2018
Merged

Conversation

IronSavior
Copy link
Contributor

Also addresses surprising maxLength behavior described in #23

@@ -103,6 +112,7 @@ function split (matcher, mapper, options) {
stream.matcher = matcher
stream.mapper = mapper
stream.maxLength = options.maxLength
stream.skipOverflow = options.skipOverflow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a stream.overflow property here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that in the morning.

index.js Outdated
if (this.overflow) {
var buf = this[kDecoder].write(chunk)
list = buf.split(this.matcher)
if (list.length === 1) return cb()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this return cb()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String#split() returns an array containing one element in exactly one case. If the length of list is 1 here, then it means the decoded chunk did not contain the matcher and we therefore want to ignore this chunk (because it followed an overflow) by returning without any push or buffering.

If we continued to buffer while overflowed, then we pay a substantial cost in terms of memory and time, which would defeat the purpose of adding this new option.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a comment explaining all of this?

@IronSavior IronSavior force-pushed the skip_overflow branch 2 times, most recently from 6939cb2 to 845b074 Compare December 12, 2018 19:33
@IronSavior
Copy link
Contributor Author

Does that make it clear? I generally like to keep explain-the-code comments to a minimum.

Also, that style linter is cranky!

Also addresses surprising maxLength behavior described in mcollina#23
Copy link
Owner

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants